/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Task2;

import Task2.iATM;
import Task2.iATMFactory;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.rmi.Naming;

/**
 *
 * @author Patrick Füssinger
 * Exercise 2 bis 21.Nov.2011
 * ITB5_2
 * 
 * Der Client holt über die RmiRegistry die ATMFactory und 
 * ruft dessen Methoden über das ihm bekannte Interface auf
 */
public class Client {

    public static void main(String[] args) {
        //CalcStub ist eine Instanc von Stub und implentiert das Calc Interface
        //und ist zum RmiSquare RemoteObjekt gebunden
        iATMFactory oATMFactory = null;
        iATM atm = null;

        try {
            
            System.out.println("IP-Adresse: ");
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            String sIPAdresse = in.readLine();
             
            //String sIPAdresse = "localhost";
            //Refernz zum RemoteObjekt holen
            oATMFactory = (iATMFactory) Naming.lookup("rmi://" + sIPAdresse + "/ATMFactory");
            
            atm = oATMFactory.createATM();

            // get initial account balance
            System.out.println("Initial Balances");
            System.out.println("Balance(1): " + atm.getBalance(1));
            System.out.println("Balance(2): " + atm.getBalance(2));
            System.out.println("Balance(3): " + atm.getBalance(3));
            System.out.println();
// make €1000 depoist in account 1 and get new balance
            System.out.println("Depositting(1): 1000 ");
            atm.deposit(1, 1000);
            System.out.println("Balance(1): " + atm.getBalance(1));
// make €100 withdrawal from account 2 and get new balance
            System.out.println("Withdrawing(2): 100 ");
            atm.withdraw(2, 100);
            System.out.println("Balance(2): " + atm.getBalance(2));
// make €500 deposit in account 3 and get new balance
            System.out.println("Depositting(3): 500 ");
            atm.deposit(3, 500);
            System.out.println("Balance(3): " + atm.getBalance(3));
// get final account balance
            System.out.println();
            System.out.println("Final Balances");
            System.out.println("Balance(1): " + atm.getBalance(1));
            System.out.println("Balance(2): " + atm.getBalance(2));
            System.out.println("Balance(3): " + atm.getBalance(3));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
